package com.whfc.iot.fse.lift.processor;

import com.whfc.common.constant.QueueConst;
import com.whfc.common.enums.DevicePlatform;
import com.whfc.common.util.JSONUtil;
import com.whfc.fse.dto.FseLiftRecordDTO;
import com.whfc.iot.fse.lift.entity.LiftMsg0x13;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2021-05-20 11:06
 */
@Component
public class LiftUpMsgProcessor0x13 implements LiftUpMsgProcessor<LiftMsg0x13> {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Override
    public void processMsg(LiftMsg0x13 msg) {
        String textMsg = JSONUtil.toString(msg);
        logger.info("处理升降机工作循环数据命令:{}", textMsg);
        try {
            FseLiftRecordDTO liftRecordDTO = new FseLiftRecordDTO();
            liftRecordDTO.setPlatform(DevicePlatform.whfciot.name());
            liftRecordDTO.setSn(msg.getDeviceSn() + "");
            liftRecordDTO.setStartTime(msg.getStartTime());
            liftRecordDTO.setEndTime(msg.getEndTime());
            liftRecordDTO.setWeight((double) msg.getWeight());
            liftRecordDTO.setPersonNo(msg.getPersonNo());
            liftRecordDTO.setStartHeight(1.0 * msg.getStartHeight() / 10);
            liftRecordDTO.setEndHeight(1.0 * msg.getEndHeight() / 10);
            liftRecordDTO.setStrokeHeight(1.0 * msg.getHeigth() / 10);
            liftRecordDTO.setAvgSpeed(1.0 * msg.getAvgSpeed() / 10);
            liftRecordDTO.setDirection(msg.getDirection());
            liftRecordDTO.setDipAngleX(1.0 * msg.getDipAngleX() / 100);
            liftRecordDTO.setDipAngleY(1.0 * msg.getDipAngleY() / 100);
            amqpTemplate.convertAndSend(QueueConst.FSE_LIFT_RECORD_DATA, JSONUtil.toString(liftRecordDTO));
        } catch (Exception ex) {
            logger.error("", ex);
        }
    }
}
